package com.lzy.rabbitmq;


import com.lzy.pojo.netty.ChatMsg;
import com.lzy.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


// 测试使用
//@Component
@Slf4j
public class RabbitMQCunsumer {

    @RabbitListener(queues = RabbitMQTestConfig.QUEUE_NAME)
    public void receive(String payload, Message message){

        log.info("payload = " + payload);

        String routingKey = message.getMessageProperties().getReceivedRoutingKey();
        log.info("routingKey = " + routingKey);

       if(routingKey.equals(RabbitMQTestConfig.ROUTING_KEY_TEST_SEND)){
           String msg = payload;
           ChatMsg chatMsg = JsonUtils.jsonToPojo(msg, ChatMsg.class);
           log.info(chatMsg.toString());
       }
    }
}
